#include <QtGui/QApplication>
#include <QTime>
#include <vector>
#include "mainwindow.h"
#include "CAs/TargetFindingCA.h"
#include "CAs/PathSmoothingCA.h"
#include "targetfindinggrid.h"

using namespace std;

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    MainWindow w;
    w.show();

    TargetFindingCA tfca;
    CA* ca=&tfca;

    /*
    vector<vector<int> > vec={
        {2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2},//2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2},
        {2,0,0,0,0,0,0,0,0,0,0,0,0,0,2,0,0,0,2,0,0,0,0,2},//0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2},
        {2,0,0,0,0,0,0,0,0,0,0,0,0,0,2,0,0,0,2,0,0,0,0,2},//0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2},
        {2,0,0,0,0,0,0,0,0,0,0,0,0,0,2,0,0,0,2,0,2,0,0,2},//0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2},
        {2,0,0,0,0,0,0,0,0,0,0,0,0,0,2,0,0,0,2,2,2,0,2,2},//0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2},
        {2,0,0,0,2,2,2,2,2,2,2,0,0,0,2,0,0,0,2,0,0,0,0,2},//0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2},
        {2,0,0,0,0,0,0,0,0,0,2,0,0,0,0,0,0,0,2,2,0,2,2,2},//0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2},
        {2,0,0,0,0,0,0,0,0,0,2,0,0,0,0,0,0,0,2,0,0,0,0,2},//0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2},
        {2,0,0,2,2,2,2,2,2,2,2,2,2,0,0,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,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2},
        {2,0,0,0,0,0,0,0,0,0,0,0,0,0,2,0,0,0,2,0,0,0,0,2},//0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2},
        {2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,0,0,0,0,2},//0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2},
        {2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2},//2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2},

    };*/



    vector<vector<int> > vec2(40,vector<int>(40));
    for(int i=0;i<40;++i)
        for(int j=0;j<40;++j)
        {
            vec2[i][j]=0;
            if((i==0) || (i==39) || (j==39) || (j==0) )vec2[i][j]=2;
            if(j==30 && i!=32)vec2[i][j]=2;
            if(j==10 && i!=10)vec2[i][j]=2;
            if(i==40 && j!=25)vec2[i][j]=2;

        }


    TargetFindingGrid grid(vec2);

    grid.set(0,32,9,1);
    grid.set(0,10,31,2);
    ca->set(grid);

    const unsigned int EVOLUTION_LIMIT=500000;

    std::vector<Grid*> evolution;

    evolution.push_back(ca->grid_copy());



    QTime myTimer;
    myTimer.start();
    while(ca->next() && evolution.size()<=EVOLUTION_LIMIT)evolution.push_back(ca->grid_copy());
    PathSmoothingCA p;
    p.set(*ca->grid_copy());
    p.start();
    evolution.push_back(p.grid_copy());
    int m = myTimer.elapsed();
    qDebug()<<m;
    w.setEvolution(evolution);

    return a.exec();
}
